package StructureData;

import java.sql.SQLException;

import po.StructurePO;
import IOHelper.DataBaseHelper;

public class StructureDataHelper extends DataBaseHelper
{

	public StructureDataHelper()
	{
		super();
	}

	public StructurePO getStructure()
	{
		StructurePO result = new StructurePO();
		String command = "SELECT * FROM Structure";
		connect();
		try
		{
			stmt = con.prepareStatement(command);
			resultset = stmt.executeQuery();
			while (resultset.next())
			{
				result.Commmon = Integer.valueOf(resultset.getString(1));
				result.Profession = Integer.valueOf(resultset.getString(2));
				result.require = Integer.valueOf(resultset.getString(3));
				result.total = Integer.valueOf(resultset.getString(4));
				result.semesterBegin = resultset.getString(5);
				result.semesterEnd = resultset.getString(6);
				result.selectLessonBegin = resultset.getString(7);
				result.selectLessonEnd = resultset.getString(8);
				result.reSelectLessonBegin = resultset.getString(9);
				result.reSelectLessonEnd = resultset.getString(10);
			}
		} catch (SQLException e)
		{
			e.printStackTrace();
		} finally
		{
			reset();
		}
		return result;
	}

	public boolean setStructure(StructurePO aim)
	{
		String command = "UPDATE Structure SET Common= " + aim.Commmon
				+ ",Profession= " + aim.Profession + ",Require =" + aim.require
				+ ",Total =" + aim.total + ",SemesterBegin ="
				+ aim.semesterBegin + ",SemesterEnd =" + aim.semesterEnd
				+ ",SelectLessonBegin =" + aim.selectLessonBegin
				+ ",SelectLessonEnd =" + aim.selectLessonEnd
				+ ",ReSelectLessonBegin =" + aim.reSelectLessonBegin
				+ ",ReSelectLessonEnd =" + aim.reSelectLessonEnd
				+ " WHERE ID=1 ";
		// System.out.println(command);
		connect();
		try
		{
			stmt = con.prepareStatement(command);
			stmt.execute();
			con.commit();
		} catch (SQLException e)
		{
			System.out.println("False");
			return false;
		} finally
		{
			reset();
		}
		System.out.println("Finish");
		return true;
	}
}
